package com.example.controller;

import com.example.entity.RestBean;
import com.example.entity.singerAndGame.GSRelative;
import com.example.entity.singerAndGame.Game;
import com.example.entity.singerAndGame.Singer;
import com.example.service.GameService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/game")
public class GameController {
    @Resource
    GameService service;

    @GetMapping("/all")
    public RestBean<List<Game>> all() {
        return RestBean.success(service.getGameList());
    }

    @PostMapping("/gid")
    public RestBean<Game> gid(int gid) {
        return RestBean.success(service.getGameByGid(gid));
    }

    @PostMapping("/game-singers")
    public RestBean<List<Singer>> gameSingers(int gid) {
        return RestBean.success(service.getGameSingerListByGid(gid));
    }

    @PostMapping("/game-judge-score")
    public RestBean<List<GSRelative>> gameScore(int gid) {
        return RestBean.success(service.getGameSingerScoreListByGid(gid));
    }

    @PostMapping("/add-step-one")
    public RestBean<String> add(@RequestBody Game game) {
        String s = service.addGameOne(game);
        if (s == null) {
            return RestBean.success("比赛信息新增成功");
        } else {
            return RestBean.failure(400, s);
        }
    }

    @PostMapping("/add-step-two")
    public RestBean<String> add(Integer gid, @RequestBody List<Integer> sid) {
        String s = service.addGameTwo(gid, sid);
        if (s == null) {
            return RestBean.success("参赛信息新增成功");
        } else {
            return RestBean.failure(400, s);
        }
    }

    @PostMapping("/judge-score")
    public RestBean<String> judgeScore(GSRelative gsRelative) {
        String s = service.setJudgeScore(gsRelative);
        if (s == null) {
            return RestBean.success("裁判评分更新成功");
        } else {
            return RestBean.failure(400, s);
        }
    }

    @PostMapping("/delete")
    public RestBean<String> delete(Integer gid) {
        String s = service.deleteGameByGid(gid);
        if (s == null) {
            return RestBean.success("比赛信息删除成功");
        } else {
            return RestBean.failure(400, s);
        }
    }
}
